package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {

	srv := gin.Default()
	srv.POST("/sms/send", func(c *gin.Context) {
		type SmsSend struct {
			Phone string `binding:"number,len=11,startswith=1,startsnotwith=11,startsnotwith=12"`
		}
		req := new(SmsSend)
		if err := c.ShouldBind(req); err != nil {
			c.JSON(http.StatusOK, err.Error())
			return
		}
		c.JSON(http.StatusOK, req)
	})

	srv.POST("/user/register", func(c *gin.Context) {
		type UserRegister struct {
			Phone      string `binding:"number,len=11,startswith=1,startsnotwith=11,startsnotwith=12"`
			Code       string `binding:"number,len=4"`
			Nickname   string `binding:"min=3,max=10"`
			Password   string `binding:"min=6,max=20"`
			RePassword string `binding:"eqfield=Password"`
		}

		req := new(UserRegister)
		if err := c.ShouldBind(req); err != nil {
			c.JSON(http.StatusOK, err.Error())
			return
		}
		c.JSON(http.StatusOK, req)
	})

	srv.POST("/user/sms/login", func(c *gin.Context) {
		type UserSmsLogin struct {
			Phone string `binding:"number,len=11,startswith=1,startsnotwith=11,startsnotwith=12"`
			Code  string `binding:"number,len=4"`
		}

		req := new(UserSmsLogin)
		if err := c.ShouldBind(req); err != nil {
			c.JSON(http.StatusOK, err.Error())
			return
		}
		c.JSON(http.StatusOK, req)
	})

	srv.POST("/user/password/login", func(c *gin.Context) {
		type UserPasswordLogin struct {
			Phone    string `binding:"number,len=11,startswith=1,startsnotwith=11,startsnotwith=12"`
			Password string `binding:"min=6,max=30"`
		}

		req := new(UserPasswordLogin)
		if err := c.ShouldBind(req); err != nil {
			c.JSON(http.StatusOK, err.Error())
			return
		}
		c.JSON(http.StatusOK, req)
	})

	srv.Run(":80")
}
